// 获取轮播图数据
import request from '@/utils/request'
import { defineStore } from 'pinia'
// 定义接口数据类型
import {
  APIRes,
  categoryResult,
  homeNewResult,
  homeHotResult
} from '@/types/data'
export default defineStore('hom', {
  state () {
    return {
      bannerList: [] as categoryResult[],
      homeNewList: [] as homeNewResult[],
      homeHotList: [] as homeHotResult[]
    }
  },
  actions: {
    async getHomeBanner () {
      const res = await request.request<APIRes<categoryResult[]>>({
        url: 'home/banner'
      })
      //    将数据存储到state中
      this.bannerList = res.data.result
    },
    // 新鲜好物数据
    async getHomeNew () {
      const res = await request.request<APIRes<homeNewResult[]>>({
        url: '/home/new'
      })
      this.homeNewList = res.data.result
    },
    // 人气推荐
    async getHomeHot () {
      const res = await request.request<APIRes<homeHotResult[]>>({
        url: '/home/hot'
      })
      this.homeHotList = res.data.result
    }
  }
})
